﻿using SW.Lite.IDAL.Master;
using SW.Lite.Infrastructure.Common;
using SW.Lite.Infrastructure.Service;
using SW.Lite.Model.Master;

namespace SW.Lite.BLL.Master
{
    public class Admin
    {
        private static readonly IAdmin Dal = ServiceLocator.Instance.GetInstance<IAdmin>("Master.Admin");

        /// <summary>
        ///     数据是否存在
        /// </summary>
        /// <param name="id"></param>
        public static bool Exists(int id)
        {
            return Dal.Exists(id);
        }

        /// <summary>
        ///     获取单个项
        /// </summary>
        /// <param name="id"></param>
        public static AdminModel Single(int id)
        {
            return Dal.Single(id);
        }

        /// <summary>
        ///     获取单个项
        /// </summary>
        /// <param name="userName">用户名</param>
        public static AdminModel Single(string userName)
        {
            return Dal.Single(userName);
        }


        /// <summary>
        ///     获取所有项目
        /// </summary>
        public static PageList<AdminModel> All()
        {
            return Dal.All();
        }

        /// <summary>
        ///     获取所有项目(分页)
        /// </summary>
        public static PageList<AdminModel> All(int pageIndex, int pageSize)
        {
            return Dal.All(pageIndex, pageSize);
        }

        /// <summary>
        ///     插入数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Insert(AdminModel model)
        {
            return Dal.Insert(model);
        }

        /// <summary>
        ///     更新数据
        /// </summary>
        /// <param name="model">单个项</param>
        public static ExecuteResult Update(AdminModel model)
        {
            return Dal.Update(model);
        }

        /// <summary>
        ///     删除数据
        /// </summary>
        /// <param name="ids">ID列表</param>
        public static ExecuteResult Delete(params int[] ids)
        {
            return Dal.Delete(ids);
        }

        /// <summary>
        ///     添加管理员角色
        /// </summary>
        /// <param name="adminId">管理员ID</param>
        /// <param name="deleteAllBeforeAdd">删除前清空已有记录</param>
        /// <param name="roleIds">角色ID列表</param>
        public static ExecuteResult AddAdminRoles(int adminId, bool deleteAllBeforeAdd, params int[] roleIds)
        {
            return Dal.AddAdminRoles(adminId, deleteAllBeforeAdd, roleIds);
        }
    }
}